package com.witte.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.witte.entity.ChancePlan;
import com.witte.entity.RespBean;
import com.witte.service.ChancePlanService;

@Controller
@ResponseBody
@RequestMapping(value="/api/chance")
@CrossOrigin
public class ChancePlanController {
	@Autowired
	ChancePlanService service;
	
	@GetMapping("/getPageData")
	public RespBean getPage(String username,int startPage,int pageSize) {
		RespBean respBean=RespBean.ok("成功",service.selectByPage(username,startPage, pageSize));
		respBean.setTotleSize(service.getTotle(username));
		return respBean;
	}
	
	@GetMapping("/searchChance")
	public RespBean searchChance(String username,String content) {
		RespBean respBean=RespBean.ok("成功",service.search(username, content));
		return respBean;
	}
	
	@PostMapping("/addPlan")
	public RespBean addPlan(@RequestBody ChancePlan chancePlan) {
		int rs=service.addPlan(chancePlan);
		if(rs>0)
			return RespBean.ok("成功");
		else
			return RespBean.ok("失败");
	}

	@GetMapping("/getPlan")
	public RespBean getPlans(String planchanceid) {
		List<ChancePlan> list=service.getPlans(planchanceid);
		return RespBean.ok("ok",list);
	}
}
